package com.atguigu.gulimall.order.web;

import com.alipay.api.AlipayApiException;
import com.atguigu.gulimall.order.config.AlipayTemplate;
import com.atguigu.gulimall.order.service.OrderService;
import com.atguigu.gulimall.order.vo.PayVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class PayWebController {

    @Autowired
    private AlipayTemplate alipayTemplate;

    @Autowired
    private OrderService orderService;

    @ResponseBody
    @GetMapping(value = "/payOrder", produces = "text/html")
    public String payOrder(@RequestParam("orderSn") String orderSn) throws AlipayApiException {
    //        PayVO vo = new PayVO();
    //        vo.setBody();//订单的备注
    //        vo.setOut_trade_no();//订单交易号
    //        vo.setSubject();//订单的主题
    //        vo.setTotal_amount();//订单的金额
        PayVO vo = orderService.getOrderPay(orderSn);
        String pay = alipayTemplate.pay(vo);
        return pay;
    }
}
